<template>
  <div>
    <van-search disabled placeholder="请输入搜索关键词" @click="$router.push('/home/popup')" />
    <div class="fenlei">
      <div class="left">
        <van-sidebar v-model="activeKey" >
          <van-sidebar-item
            v-for="item in categoryList"
            :key="item.id"
            :title="item.name"
            @click="changeFn(item.id)"
          />
        </van-sidebar>
      </div>
      <div class="right">
        <div class="image">
          <img :src="currentCategory.banner_url" alt="" />
          <p>{{ currentCategory.front_desc }}</p>
        </div>
        <div class="title">
          <h3>{{ currentCategory.name }}</h3>
          <span></span>
        </div>
        <div class="grid">
          <van-grid :column-num="3">
            <van-grid-item
              v-for="item in currentCategory.subCategoryList"
              :key="item.id"
              :icon="item.wap_banner_url"
              :text="item.name"
            />
          </van-grid>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getcatelogList, getCurrent } from '@/api/category'
export default {
  name: 'categoryBar',
  data () {
    return {
      activeKey: 0,
      categoryList: [],
      currentCategory: {},
      subCategoryList: []
    }
  },
  methods: {
    async getList () {
      const res = await getcatelogList()
      this.categoryList = res.data.categoryList
      this.currentCategory = res.data.currentCategory
      this.subCategoryList = res.data.currentCategory.subCategoryList
    },
    async changeFn (id) {
      const res = await getCurrent({ id: id })
      this.currentCategory = res.data.currentCategory
      this.subCategoryList = res.data.subCategoryList
    }
  },
  created () {
    this.getList()
  }
}
</script>

<style lang='less' scoped>
.fenlei {
  width: 100%;
  background-color: #fff;
  height: 90vh;
  display: flex;
  .left {
    width: 20%;
  }
  .right {
    width: 80%;
    .image {
      position: relative;
      img {
        width: 95%;
        height: 1.4rem;
        margin: 0 0.07rem;
        border-radius: 0.05rem;
        box-shadow: 0 0 0.06rem #000;
        filter: brightness(0.5);
      }
      p {
        width: 100%;
        text-align: center;
        position: absolute;
        top: 49%;
        color: #fff;
        left: 0;
        font-size: 0.14rem;
      }
    }
    .title {
      width: 100%;
      font-size: 0.14rem;
      height: 0.5rem;
      position: relative;
      h3 {
        width: 30%;
        text-align: center;
        background-color: #fff;
        height: 0.4rem;
        line-height: 0.4rem;
        position: absolute;
        margin: auto;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
      }
      span {
        width: 50%;
        height: 0.02rem;
        background-color: #ccc;
        position: absolute;
        margin: auto;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
      }
    }
  }
}
</style>
